-- Wakuse
-- Created by cheny3 Aug/26/2016
-- 变异体冈布奥

-- 初始化
function initWakuse(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    -- 获取变异体信息
    local wakuseiId = self.gridData.wakusei_id;
    local petId = WakuseiM.query(wakuseiId, "pet_id");
    local petIcon = PetM.getDefaultIcon(petId);
    local iconPath = getHeroIconPath(petIcon);

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.ended then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 更新建筑访问
            self:updateBuildingVisit();

            local function exchange()
                DungeonActionM.go("wakusei_exchange", self.gridData:getPos());
            end

            local title = PetM.query(petId, "name");
            local dialog = WakuseiM.query(wakuseiId, "dialog");

            -- 打开建筑界面
            self:openBuildingView(exchange, 0, dialog, nil, title, iconPath, nil, nil, {["scale"] = 1.18});

            -- 音效
            AudioM.playFx("ui_open1");
        end
    end

    -- 创建冈布奥的图片
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
    self.needAnimation = true;
    self.icon:setScale(1.18);
    self.icon:setPositionY(-5);
end
